﻿using ApplicationLibrary;
using ApplicationLibrary.SqlConnector;

namespace Fighter.Masters.ModuleData
{
    #region RRMasterType

    public class RRDesctiptionType : DataReaderUpdater
    {
        private DescriptionType type;
        private SqlABParameter sqlP1;

        public RRDesctiptionType(DescriptionType type)
            : base(false)
        {
            this.type = type;
        }

        protected override void CreateConnection()
        {
            myTable = FG_Descriptions.Name;

            QueryBuilder qb = new QueryBuilder();
            sqlP1 = new SqlABParameter("@p51", FG_Descriptions.Type);

            qb.AddSelect();
            qb.AddFrom(FG_Descriptions.Name);
            qb.AddCompare(FG_Descriptions.Type, sqlP1);
            qb.AddOrder(FG_Descriptions.Description);

            sqlCM = new SqlABCommand(qb.Query, sqlCN);
            sqlCM.Parameters.Add(sqlP1);
            sqlDA = new SqlABDataAdapter(sqlCM);

        }

        protected override void SetParameters()
        {
            sqlP1.Value = type;
        }
    }

    #endregion

    #region RRClub

    public class RRClub : DataReaderUpdater
    {
        public RRClub()
            : base(false)
        {
        }

        protected override void CreateConnection()
        {
            myTable = FG_Club.Name;

            QueryBuilder qb = new QueryBuilder();

            qb.AddSelect();
            qb.AddFrom(FG_Club.Name);
            qb.AddOrder(FG_Club.Club);

            sqlCM = new SqlABCommand(qb.Query, sqlCN);
            sqlDA = new SqlABDataAdapter(sqlCM);
        }

        protected override void SetParameters()
        {
        }
    }

    #endregion

    #region DRClub

    public class DRClub : DataReaderUpdater
    {
        private SqlABParameter sqlP1;
        private string mail;

        public DRClub(bool updater = false)
            : base(updater)
        {
        }

        protected override void CreateConnection()
        {
            myTable = FG_Club.Name;

            QueryBuilder qb = new QueryBuilder();
            sqlP1 = new SqlABParameter("@p51", FG_Club.Mail);

            qb.AddSelect();
            qb.AddFrom(FG_Club.Name);
            qb.AddCompare(FG_Club.Mail, sqlP1);

            sqlCM = new SqlABCommand(qb.Query, sqlCN);
            sqlCM.Parameters.Add(sqlP1);
            sqlDA = new SqlABDataAdapter(sqlCM);

        }

        protected override void SetParameters()
        {
            sqlP1.Value = mail;
        }

        public bool Find(string mail)
        {
            this.mail = mail;
            return base.Find();
        }
    }

    #endregion

    #region DRAthlete
    public class DRAthlete : DataReaderUpdater
    {
        private SqlABParameter sqlP1;
        private int idAthlete;

        public DRAthlete(bool updater = false)
            : base(updater)
        {
        }

        protected override void CreateConnection()
        {
            myTable = FG_Athlete.Name;

            QueryBuilder qb = new QueryBuilder();
            sqlP1 = new SqlABParameter("@p51", FG_Athlete.ID);

            qb.AddSelect();
            qb.AddFrom(FG_Athlete.Name);
            qb.AddCompare(FG_Athlete.ID, sqlP1);

            sqlCM = new SqlABCommand(qb.Query, sqlCN);
            sqlCM.Parameters.Add(sqlP1);
            sqlDA = new SqlABDataAdapter(sqlCM);

        }

        protected override void SetParameters()
        {
            sqlP1.Value = idAthlete;
        }

        public bool Find(int idAthlete)
        {
            this.idAthlete = idAthlete;
            return base.Find();
        }
    }

    #endregion

    #region DUCoach
    public class DUCoach : DataReaderUpdater
    {
        private SqlABParameter sqlP1, sqlP2;
        private string mail;
        int line;

        public DUCoach(bool updater = true)
            : base(updater)
        {
        }

        protected override void CreateConnection()
        {
            myTable = FG_Athlete.Name;

            QueryBuilder qb = new QueryBuilder();
            sqlP1 = new SqlABParameter("@p51", FG_Coach.Mail);
            sqlP2 = new SqlABParameter("@p52", FG_Coach.Line);

            qb.AddSelect();
            qb.AddFrom(FG_Coach.Name);
            qb.AddCompare(FG_Coach.Mail, sqlP1);
            qb.AddCompare(FG_Coach.Line, sqlP1);

            sqlCM = new SqlABCommand(qb.Query, sqlCN);
            sqlCM.Parameters.Add(sqlP1);
            sqlCM.Parameters.Add(sqlP2);
            sqlDA = new SqlABDataAdapter(sqlCM);
        }

        protected override void SetParameters()
        {
            sqlP1.Value = mail;
            sqlP2.Value = line;
        }

        public bool Find(string mail, int line)
        {
            this.mail = mail;
            this.line = line;
            return base.Find();
        }
    }

    #endregion

    #region RRAthleteForClub

    public class RRAthleteForClub : DataReaderUpdater
    {
        private SqlABParameter sqlP1;
        private string mail;

        public RRAthleteForClub()
            : base(false)
        {
        }

        protected override void CreateConnection()
        {
            myTable = FG_Athlete.Name;

            QueryBuilder qb = new QueryBuilder();
            sqlP1 = new SqlABParameter("@p51", FG_Athlete.Mail);

            qb.AddSelect();
            qb.AddFrom(FG_Athlete.Name);
            qb.AddCompare(FG_Athlete.Mail, sqlP1);
            qb.AddOrder(FG_Athlete.FirstName);

            sqlCM = new SqlABCommand(qb.Query, sqlCN);
            sqlCM.Parameters.Add(sqlP1);
            sqlDA = new SqlABDataAdapter(sqlCM);
        }

        protected override void SetParameters()
        {
            sqlP1.Value = mail;
        }

        public bool Find(string mail)
        {
            this.mail = mail;
            return base.Find();
        }
    }

    #endregion
    #region RRCoachForClub

    public class RRCoachForClub : DataReaderUpdater
    {
        private SqlABParameter sqlP1;
        private string mail;

        public RRCoachForClub()
            : base(false)
        {
        }

        protected override void CreateConnection()
        {
            myTable = FG_Coach.Name;

            QueryBuilder qb = new QueryBuilder();
            sqlP1 = new SqlABParameter("@p51", FG_Coach.Mail);

            qb.AddSelect();
            qb.AddFrom(FG_Coach.Name);
            qb.AddCompare(FG_Coach.Mail, sqlP1);
            qb.AddOrder(FG_Coach.FirstName);

            sqlCM = new SqlABCommand(qb.Query, sqlCN);
            sqlCM.Parameters.Add(sqlP1);
            sqlDA = new SqlABDataAdapter(sqlCM);
        }

        protected override void SetParameters()
        {
            sqlP1.Value = mail;
        }

        public bool Find(string mail)
        {
            this.mail = mail;
            return base.Find();
        }
    }

    #endregion

}